import java.util.Arrays;

public class insertsort {
    public static void insert(int[] arr){
        for (int i = 1; i < arr.length; i++) {
            int val = arr[i];
            int count = i-1;
            while (count>=0 && val<arr[count]){
                arr[count+1] = arr[count];
                count--;
            }
            arr[count+1] = val;
        }
    }
    
    public static void main(String[] args) {
        int[] arr = {6,4,7,-1,14,-2};
        insert(arr);
        System.out.println(Arrays.toString(arr));
    }

}
